<?php
/**
 *
 * @author Forrest
 * @version 
 */
require_once 'Zend/View/Interface.php';
/**
 * Hyperlink helper
 *
 * @uses viewHelper Dig_View_Helper
 */
class Dig_View_Helper_Hyperlink extends Zend_View_Helper_HtmlElement
{
    /**
     * @var Zend_View_Interface 
     */
    public $selectedClass = 'selected';
    public $view;
    /**
     *  
     */
    public function hyperlink ($href, $label, $selected = null, $target = null, array $attribs = array())
    {
        $attribs['href'] = $href;
        if ($selected === null) {
            $request = $_SERVER['REQUEST_URI'];
            if ($href == $request) {
                $selected = true;
            } else {
                $selected = false;
            }
        }
        if ($selected == true) {
            if (isset($attribs['class'])) {
                $attribs['class'] .= ' ' . $this->selectedClass;
            } else {
                $attribs['class'] = $this->selectedClass;
            }
        }
        if ($target != null) {
            $attribs['target'] = $target;
        }
        // render hyperlink
        // @todo: escape the label
        $xhtml = '<a' . $this->_htmlAttribs($attribs) . '>' . $label . '</a>';
        return $xhtml;
    }
}
